package edu.mju.eduservice.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import edu.mju.eduservice.entity.StudyTeacher;
import edu.mju.eduservice.mapper.StudyTeacherMapper;
import edu.mju.eduservice.service.StudyTeacherService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author xiaoxin
 * @since 2020-08-24
 */
@Service
public class StudyTeacherServiceImpl extends ServiceImpl<StudyTeacherMapper, StudyTeacher> implements StudyTeacherService {

    @Override
    public Map<String, Object> getTeacherList(Page<StudyTeacher> studyTeacherPage) {
        QueryWrapper<StudyTeacher> wrapper = new QueryWrapper<>();
        wrapper.orderByDesc("level");
        baseMapper.selectPage(studyTeacherPage,wrapper);

        List<StudyTeacher> records = studyTeacherPage.getRecords();
        long current = studyTeacherPage.getCurrent();
        long pages = studyTeacherPage.getPages();
        long size = studyTeacherPage.getSize();
        long total = studyTeacherPage.getTotal();
        boolean hasNext = studyTeacherPage.hasNext();
        boolean hasPrevious = studyTeacherPage.hasPrevious();

        //分页数据放到map中
        Map<String,Object> map = new HashMap<>();
        map.put("records",records);
        map.put("current",current);
        map.put("pages",pages);
        map.put("size",size);
        map.put("total",total);
        map.put("hasNext",hasNext);
        map.put("hasPrevious",hasPrevious);


        return map;
    }
}
